package com.group9.handinhand.dao.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang.ArrayUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.group9.handinhand.service.so.OfferResponseSO;

@Entity
@Table(name = "OFFER_RESPONSE")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class OfferResponse extends AbstractBaseModel {

	private static final long serialVersionUID = 1L;

	@ManyToOne
	@JoinColumn(name = "USER_ID", nullable = false)
	private User user;
	
	@ManyToOne
	@JoinColumn(name = "OFFER_ID", nullable = false)
	private Offer offer;
	
	@Column(name = "RESPOND_AMOUNT", nullable = false)
	private int respondAmount;
	
	public OfferResponseSO convertToServiceObject(String... ignoreProperties) {
		OfferResponseSO so = (OfferResponseSO) convert(new OfferResponseSO(), 
			(String[]) ArrayUtils.addAll(ignoreProperties, new String[]{"request","user"}));
		so.setOffer(offer.convertToServiceObject(new String[]{"moderators", "posts"}));
		so.setUser(user.convertToServiceObject(new String[]{"socialUsers"}));
		return so;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Offer getOffer() {
		return offer;
	}

	public void setOffer(Offer offer) {
		this.offer = offer;
	}

	public int getRespondAmount() {
		return respondAmount;
	}

	public void setRespondAmount(int respondAmount) {
		this.respondAmount = respondAmount;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	@Override
	public String toString() {
		return "OfferResponse [user=" + user + ", offer=" + offer
				+ ", respondAmount=" + respondAmount + "]";
	}

}
